﻿using Kn.DLMS;
using Kn.DLMS.Internal;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsApplication3;


namespace Kn.ALICE
{

    /**
    * @brief AT work running state.
    */
    public enum AtWorkState
    {
        AT_WORK_STAT_IDLE,
        AT_WORK_STAT_READY,
        AT_WORK_STAT_RUN,
        AT_WORK_STAT_FINISH,
        AT_WORK_STAT_ABORT
    }

    /**
     * @brief AT command response code
     */
    public enum AtRespCode
    {
        AT_RESP_OK = 0,
        AT_RESP_ERROR,
        AT_RESP_TIMEOUT,
        AT_RESP_ABORT
    }

    /**
    * @brief AT work type (corresponding to different state machine polling handler.)
    * 对应于不同状态机的轮询处理程序的AT工作类型
    */
    public enum WorkType
    {
        WORK_TYPE_GENERAL = 0,       /* General work */
        WORK_TYPE_SINGLLINE,         /* Singlline command */
        WORK_TYPE_MULTILINE,         /* Multiline command */
        WORK_TYPE_CMD,               /* Standard command */
        WORK_TYPE_CUSTOM,            /* Custom command */
        WORK_TYPE_BUF,               /* Buffer */
        WORK_TYPE_MAX
    }

    /**
    * @brief AT command execution state.
    * 命令执行状态
    */
    public enum AtCmdState
    {
        AT_STAT_SEND = 0,
        AT_STAT_RECV,
        AT_STAT_RETRY
    }

    /**
    * @brief AT execution callback
    * @param r AT response information (including execution results, content information returned by the device)
    */
    public class at_response_t
    {
        //public at_obj obj;
        public object Params;
        public AtRespCode code;
        public ushort recvcnt;
        public string recvbuf;
        public string prefix;
        public string suffix;
    }

    public delegate void at_callback_t(ref at_response_t r);


    public class at_attr_t
    {
        public object Params { get; set; } // 用户参数，如果不需要，可以将其设置为null
        public string Prefix { get; set; } // 响应前缀，如果不需要，可以将其设置为null
        public string Suffix { get; set; } // 响应后缀，如果不需要，可以将其设置为null
        public at_callback_t Callback { get; set; } // 响应回调处理函数，如果不需要，可以将其设置为null
        public ushort Timeout { get; set; } // 响应超时时间（毫秒）
        public byte Retry { get; set; } // 响应错误重试次数
        //public at_cmd_priority Priority { get; set; } // 命令执行优先级
    }

  
    public struct work_item_t
    {
        public at_attr_t attr;          // 工作项的属性
        public ushort magic;            // AT魔术数，用于标识工作项
        public byte state;              // 工作项的状态
        public byte type;               // 工作项的类型
        public byte code;               // 响应代码
        public byte life;               // 生命周期倒计时，表示工作项的剩余生命周期
        public byte dirty;              // 脏标志，表示工作项是否被修改
    }

    /// <summary>
    /// Public environment for AT work 
    /// </summary>
    public class at_env_t
    {
        //public at_obj_t obj;
        public int i;
        public int j;
        public int state;
        public IntPtr paramsPtr;
        public Action<at_env_t, uint> next_wait;
        public Action<at_env_t> reset_timer;
        public Func<at_env_t, uint, bool> is_timeout;
        public Action<at_env_t, string> println;
        public Func<at_env_t, string, string> contains;
        public Func<at_env_t, string> recvbuf;
        public Func<at_env_t, uint> recvlen;
        public Action<at_env_t> recvclr;
        public Func<at_env_t, bool> disposing;
        //public Action<at_env_t, at_resp_code> finish;
     
    }



}


